<?php


/**
 * this file provides some usful function for all applications
 * 
 * @author		simon ungerboeck <ungerboeck_simon@hotmail.com>
 * @version		1.0
 */

/*
 * checks if database type is mysql
 * @return		 bool		$isMySql
 */
function isMySql() {
	$isMySql = false;
	if (defined('DB_TYPE') and defined('MYSQL') and DB_TYPE == MYSQL)
		$isMySql = true;
	return $isMySql;
}


/*
 * checks if database type is mssql
 * @return		 bool		$isMsSql
 */
function isMsSql() {
	$isMsSql = false;
	if (defined('DB_TYPE') and defined('MSSQL') and DB_TYPE == MSSQL)
		$isMsSql = true;
	return $isMsSql;
}


/*
 * checks if database type is oracle
 * @return		 bool		$isOracle
 */
function isOracle() {
	$isOracle = false;
	if (defined('DB_TYPE') and defined('ORACLE') and DB_TYPE == ORACLE)
		$isOracle = true;
	return $isOracle;
}


/**
 * returns the application id of defined application name
 * @return		int		$applicationId
 */
function getApplicationId() {
	$applicationId = 0;
	
	if (defined('APPLICATION')) {
		$sql = 'select application_id from ' . DB_CORE . '.application where upper(name)=upper(?)';
		$params = array(APPLICATION);
		$sqlObj = Sql_Object::getInstance();
		$sqlObj->connect();
		$sqlObj->execute($sql, $params);
		if (($row = $sqlObj->fetch()) != null)
			$applicationId = $row['application_id'];
		$sqlObj->disconnect();
	}
	return $applicationId;
}


/**
 * returns a string in double digit format: 1 -> 01
 * @param 		int		 $number
 * @return		string
 */
function getDoubleDigitFormat($number){
	return ((intval($number) < 10) ? str_pad($number, 2, '0', STR_PAD_LEFT) : $number);
}

?>